//
//  SectionedTitleContentViewController.swift
//  HuaYun
//
//  Created by enghou on 2018/10/11.
//  Copyright © 2018年 xyxorigation. All rights reserved.
//

import UIKit

class SectionedTitleContentViewController: UITableViewController {
    
    var source: Array<Array<String>> = []
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.tableView.register(UINib.init(nibName: "ApprovalDetailCell", bundle: Bundle.main), forCellReuseIdentifier: "ApprovalDetailCell")
        self.tableView.tableFooterView = UIView()
        self.tableView.reloadData()
    }
    // MARK: - Table view data source

    override func numberOfSections(in tableView: UITableView) -> Int {
        // #warning Incomplete implementation, return the number of sections
        return source.count
    }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of rows
        return source[section].count
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        return tableView.dequeueReusableCell(withIdentifier: "ApprovalDetailCell")!
    }
    
    override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
        if let cel = cell as? ApprovalDetailCell {
            
            cel.detailLbl.text = source[indexPath.section][indexPath.row]
            switch indexPath.row{
            case 0:
                cel.titleLbl.text = "日期"
            case 1:
                cel.titleLbl.text = "记录人"
            default:
                cel.titleLbl.text = "描述"
                
            }
        }
    }
    
    override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        let string = source[indexPath.section][indexPath.row]
        if string.count > 0 {
            let size = string.size(with: UIFont.systemFont(ofSize: 15), maxSize: CGSize.init(width: tableView.width - 40, height: 1000000))
            
            return 55 + size.height
        }
        return 65
    }
    
    override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 10
    }
    
    override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        let view = UIView()
        view.backgroundColor = UIColor.hex("eeeeee")
        return view
    }

}
